home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / cmln0885.arc / SMALTAL1.LTG < prev    next >
Text File  |  1986-02-27  |  2KB  |  46 lines

  1.  
  2. Smalltalk LISTING 1:  
  3.           
  4.           Filter class definition and methods
  5.  
  6.           Object subclass: #Filter
  7.             instanceVariableNames:
  8.               'filterBlock '        "Code that does the filtering"
  9.             classVariableNames: ''  "None"
  10.             poolDictionaries: ''    "None"
  11.  
  12.           Filter class methods
  13.  
  14.           using: aFilterBlock
  15.  
  16.             "Create a new filter using the specified block."
  17.              ^self new using: aFilterBlock
  18.  
  19.  
  20.           Filter methods
  21.  
  22.           from: inStream to: outStream
  23.  
  24.             "Filter from input to output stream, returning output
  25.              stream."
  26.              inStream do: [:item |   "Do for each item in inStream"
  27.                ((item := filterBlock value: item) isKindOf: String)
  28.                  ifTrue:  [outStream nextPutAll: item]
  29.                  ifFalse: [outStream nextPut: item]].
  30.              ^outStream.
  31.  
  32.           fromFile: inFile toFile: outFile
  33.  
  34.             "Filter from the specified input file and append to the
  35.              output file. Return the output file name."
  36.             ^(self        "Invoke self with files opened as streams"
  37.                from: (Disk file: inFile)
  38.                to:   (Disk file: outFile) setToEnd)
  39.               close file name.
  40.  
  41.           using: aFilterBlock
  42.  
  43.             "Make the specified block be this object's filter block."
  44.              filterBlock := aFilterBlock
  45.  
  46.